﻿5
<script>
    function showObject(obj, k) {
        //递归显示object
        alert("a");
        if (!obj) { return; }
        for (var i in obj) {
            if (typeof (obj[i]) != "object" || obj[i] == null) {
                for (var j = 0; j < k; j++) {
                    document.write("&nbsp;&nbsp;&nbsp;&nbsp;");
                }
                document.write(i + " : " + obj[i] + "<br/>");
            } else {
                document.write(i + " : " + "<br/>");
                showObject(obj[i], k + 1);
            }
        }
    }
    function get_location() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(show_map, handle_error, { enableHighAccuracy: true, maximumAge: 1000 });
        } else {
            alert("Your browser does not support HTML5 geoLocation");
        }
    }
    function handle_error(err) {
        //错误处理
        switch (err.code) {
            case 1:
                alert("permission denied");
                break;
            case 2:
                alert("the network is down or the position satellites can't be contacted");
                break;
            case 3:
                alert("time out");
                break;
            default:
                alert("unknown error");
                break;
        }
    }
    function show_map(position) {
        //显示地理信息
        var latitude = position.coords.latitude;
        var longitude = position.coords.longitude;
        showObject(position, 0);
    }
    get_location();
</script>